package com.itany.cloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/8/10 9:05
 * Version:1.0-SNAPSHOT
 * Description:
 */
@Configuration
@EnableSwagger2 // 启用Swagger2的配置
public class SwaggerConfig {

    @Bean
    public Docket createRestful(){
        return new Docket(DocumentationType.SWAGGER_2)
                // 设置文档信息
                .apiInfo(apiInfo())
                // 扫描指定包中Swagger的注解
                .select()
                // 指定包名
                .apis(RequestHandlerSelectors.basePackage("com.itany.cloud.controller"))
                // 设置扫描方式,级联
                .paths(PathSelectors.any())
                .build();

    }

    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                // 设置标题信息
                .title("用户功能接口文档")
                // 设置详细的描述信息
                .description("这是使用Swagger2构建的基于Restful API的用户功能相关的接口文档")
                // 设置联系人信息
                .contact(new Contact("admin","https://www.baidu.com/","123456@qq.com"))
                // 设置版本号
                .version("1.0")
                .build();
    }

}
